package sel.me.spring.boot159.web.component;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @author shenenlu 2021年04月26日 下午14:26:58
 */
@Component
@DefaultProperties(defaultFallback = "getGlobalError")
public class OuterRestApiInvoker {

    @Autowired
    @Qualifier("outerRestTemplate")
    private RestTemplate outerRestTemplate;


//    @HystrixCommand
    @HystrixCommand(fallbackMethod = "getError")
//    @HystrixCommand(commandKey = "testCommand", groupKey = "testGroup", threadPoolKey = "testThreadKey",
//            fallbackMethod = "getError", ignoreExceptions = {NullPointerException.class},
//            threadPoolProperties = {
//                    @HystrixProperty(name = "coreSize", value = "30"),
//                    @HystrixProperty(name = "maxQueueSize", value = "101"),
//                    @HystrixProperty(name = "keepAliveTimeMinutes", value = "2"),
//                    @HystrixProperty(name = "queueSizeRejectionThreshold", value = "15"),
//                    @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "12"),
//                    @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1440")
//            }
//    )
//    @HystrixCommand(fallbackMethod = "getError", commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
//    })
    public String getHello(int id){
        return outerRestTemplate.getForEntity("http://aaa.com", String.class).getBody();
    }

    public String getError(int id) {
        return "hello,sorry,getError!: " + id;
    }

    public String getGlobalError() {
        return "hello,sorry,getGlobalError!";
    }

}
